<?php  
class ControllerProductProduct extends Controller {
	private $error = array(); 
	
	public function index() {         
		$this->language->load('product/product');     				
		$this->document->breadcrumbs = array();
        unset($this->session->data['in_stock']);

        /*
		$this->document->breadcrumbs[] = array(
			'href'      => HTTP_SERVER . 'index.php?route=common/home',
			'text'      => $this->language->get('text_home'),
			'separator' => FALSE
		);
		*/   
		$this->load->model('tool/seo_url');   		
		$this->load->model('catalog/category');			
        
		if (isset($this->request->get['path'])) {
			$path = '';
				
			foreach (explode('_', $this->request->get['path']) as $path_id) {
				$category_info = $this->model_catalog_category->getCategory($path_id);
				
				if (!$path) {
					$path = $path_id;
				} else {
					$path .= '_' . $path_id;
				}
				/*
				if ($category_info) {
					$this->document->breadcrumbs[] = array(
						'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $path),
						'text'      => $category_info['name'],
						'separator' => $this->language->get('text_separator')
					);
				}
                */
			}
            
            $categories_list = explode('_', $this->request->get['path']);
            $this->document->breadcrumbs = $this->model_catalog_category->createBreadcrumbs($categories_list);
            /*
            $breadcrumbs = explode('_', $this->request->get['path']);
            $breadcrumb_path = '';
            foreach($breadcrumbs as $breadcrumb){
                $separator = $breadcrumb_path ? ' >> '  : false;
                $breadcrumb_path = $breadcrumb_path ? ($breadcrumb_path . '_' . $breadcrumb) : $breadcrumb;
                
                $this->document->breadcrumbs[] = array(
                    'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/categories&path=' . $breadcrumb_path),
                    'text'      => $this->model_catalog_category->getCategoryName($breadcrumb),
                    'separator' => $separator,
                );
            }  
            */         
		}
		
		$this->load->model('catalog/manufacturer');			
		if (isset($this->request->get['manufacturer_id'])) {        
			$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);

            /*
			if ($manufacturer_info) {	
				$this->document->breadcrumbs[] = array(					
                    'href'        => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/manufacturer&viewManufacturer&manufacturer_id=' . $this->request->get['manufacturer_id']),
					'text'	    => $manufacturer_info['name'],
					'separator' => $this->language->get('text_separator')
				);
			}
            */
		}
        
		if (isset($this->request->get['keyword'])) {
			$url = '';

			if (isset($this->request->get['category_id'])) {
				$url .= '&category_id=' . $this->request->get['category_id'];
			}	
			
			if (isset($this->request->get['description'])) {
				$url .= '&description=' . $this->request->get['description'];
			}
			/*
			$this->document->breadcrumbs[] = array(
				'href'      => HTTP_SERVER . 'index.php?route=product/search&keyword=' . $this->request->get['keyword'] . $url,
				'text'      => $this->language->get('text_search'),
				'separator' => $this->language->get('text_separator')
			);
            */	
		}
        
		$this->data['template'] = $this->config->get('config_template');  
        
		$this->load->model('catalog/product');
		
		if (isset($this->request->get['product_id'])) {
			$product_id = $this->request->get['product_id'];
		} else {
			$product_id = 0;
		}
		
		$product_info = $this->model_catalog_product->getProduct($product_id);
		
		if ($product_info) {
			$url = '';
			$path = '';
			if (isset($this->request->get['path'])) {
				$url .= '&path=' . $this->request->get['path'];
                $path .= '&path=' . $this->request->get['path'];
			}
			
			if (isset($this->request->get['manufacturer_id'])) {
				$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
			}			

			if (isset($this->request->get['keyword'])) {
				$url .= '&keyword=' . $this->request->get['keyword'];
			}			

			if (isset($this->request->get['category_id'])) {
				$url .= '&category_id=' . $this->request->get['category_id'];
			}
				
			if (isset($this->request->get['description'])) {
				$url .= '&description=' . $this->request->get['description'];
			}				
									
			$this->document->breadcrumbs[] = array(
				'href'      => '', //$this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $this->request->get['product_id']),
				'text'      => $product_info['name'],
				//'separator' => $this->language->get('text_separator')
                'separator' => ' >> ',
			);			
			
			$this->document->title = $product_info['name'];			
			$this->document->keywords = $product_info['meta_keywords'];			
			$this->document->description = $product_info['meta_description'];			

			$this->data['heading_title'] = $product_info['name'];
            //$shortname = (strlen($product_info['name']) < 61) ? $product_info['name'] : substr($product_info['name'], 0 ,61) . ' ...';                         
            //$shortname = $this->model_catalog_product->breakProductName($product_info['name'], 57);
            //$shortname = $this->model_catalog_product->productShortName($product_info['name'], 57);
			$shortname = $product_info['name'];
            $this->data['short_title'] = $shortname; 

			$this->data['text_enlarge'] = $this->language->get('text_enlarge');
			$this->data['text_discount'] = $this->language->get('text_discount');
			$this->data['text_options'] = $this->language->get('text_options');
			$this->data['text_price'] = $this->language->get('text_price');
			$this->data['text_availability'] = $this->language->get('text_availability');
			$this->data['text_model'] = $this->language->get('text_model');
			$this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
			$this->data['text_order_quantity'] = $this->language->get('text_order_quantity');
			$this->data['text_price_per_item'] = $this->language->get('text_price_per_item');
			$this->data['text_qty'] = $this->language->get('text_qty');
			$this->data['text_write'] = $this->language->get('text_write');
			$this->data['text_average'] = $this->language->get('text_average');
			$this->data['text_no_rating'] = $this->language->get('text_no_rating');
			$this->data['text_note'] = $this->language->get('text_note');
			$this->data['text_no_images'] = $this->language->get('text_no_images');
			$this->data['text_no_related'] = $this->language->get('text_no_related');
			$this->data['text_wait'] = $this->language->get('text_wait');
			$this->data['text_tags'] = $this->language->get('text_tags');
			$this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);

			$this->data['entry_name'] = $this->language->get('entry_name');
			$this->data['entry_review'] = $this->language->get('entry_review');
			$this->data['entry_rating'] = $this->language->get('entry_rating');
			$this->data['entry_good'] = $this->language->get('entry_good');
			$this->data['entry_bad'] = $this->language->get('entry_bad');
			$this->data['entry_captcha'] = $this->language->get('entry_captcha');

			$this->data['button_continue'] = $this->language->get('button_continue');
			
			$this->load->model('catalog/review');

			$this->data['tab_description'] = $this->language->get('tab_description');
			$this->data['tab_image'] = $this->language->get('tab_image');
			$this->data['tab_review'] = sprintf($this->language->get('tab_review'), $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']));
			$this->data['tab_related'] = $this->language->get('tab_related');
			
			if ($this->config->get('config_review')) {
				$average = $this->model_catalog_review->getAverageRating($this->request->get['product_id']);	
			} else {
				$average = false;
			}
			
			$this->data['review_status'] = $this->config->get('config_review');
			
			$this->data['text_stars'] = sprintf($this->language->get('text_stars'), $average);
			
			$this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');

			$this->data['action'] = HTTP_SERVER . 'index.php?route=checkout/cart';
			$this->data['checkout'] = HTTP_SERVER . 'index.php?route=checkout/cart';
			$this->data['redirect'] = HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $this->request->get['product_id'];
			$this->data['success_url'] = HTTP_SERVER . 'index.php?route=product/product/addsuccess' . $path . '&product_id=' . $product_info['product_id'];
            $this->data['next_step'] = HTTP_SERVER . 'index.php?route=checkout/cart';
			$this->data['current_url'] = urldecode($this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $product_info['product_id']));
            
			$this->load->model('tool/image');

			if ($product_info['image']) {
				$image = $product_info['image'];
			} else {
				$image = 'no_image.jpg';
			}	
					
			$this->data['popup'] = $this->model_tool_image->resize($image, $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
			//$this->data['thumb'] = $this->model_tool_image->resize($image, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
            //$this->data['thumb'] = $this->model_tool_image->resize($image, 220, 316);
            $this->data['thumb'] = $this->model_tool_image->resize($image, 285, 346);

			$this->data['product_info'] = $product_info;			    
             
            /*           
			$discount = $this->model_catalog_product->getProductDiscount($this->request->get['product_id']);			
			if ($discount) {
				$this->data['price'] = $this->currency->formatPrice($this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax')));
                $this->data['price_ref'] = $this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax'));
				
				$this->data['special'] = FALSE;
			} else {        
				$this->data['price'] = $this->currency->formatPrice($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
                $this->data['price_ref'] = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'));
			
				$special = $this->model_catalog_product->getProductSpecial($this->request->get['product_id']);
			
				if ($special) {
					$this->data['special'] = $this->currency->formatPrice($this->tax->calculate($special, $product_info['tax_class_id'], $this->config->get('config_tax')));
				} else {
					$this->data['special'] = FALSE;
				}
			}
			*/
            $this->data['price'] = $this->currency->formatPrice($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
            $this->data['price_ref'] = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'));
            $this->data['discount'] =  0;
            
            $p_price = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'));
            $p_discount = 0;
                
            $this->load->model('catalog/discount');
            $discount = $this->model_catalog_discount->getDiscount($this->request->get['product_id']);
            
            if($discount > 0){
                $this->data['discount'] = $this->currency->formatPrice($this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax'))); 
                $this->data['price_ref'] = $discount;
                $p_discount = $discount;
            }
            
            
            
			$discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']); 			
            if($discounts){
                $this->data['price_ref'] = $discounts[0]['price']; 
                $this->data['discount'] = $this->currency->formatPrice($this->tax->calculate($discounts[0]['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
                $p_discount = $discounts[0]['price'];
            }
            
			$this->data['discounts'] = array();   			
			foreach ($discounts as $discount) {
				$this->data['discounts'][] = array(
					'quantity' => $discount['quantity'],
					'price'    => $this->currency->formatPrice($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
				);
			}

			$this->data['save_price'] = $this->currency->formatPrice(($p_price - $p_discount));
             
            $special = $this->model_catalog_product->getProductSpecial($this->request->get['product_id']);        
            if ($special) {
                $this->data['special'] = $this->currency->formatPrice($this->tax->calculate($special, $product_info['tax_class_id'], $this->config->get('config_tax')));
            } else {
                $this->data['special'] = FALSE;
            }
                 
			if ($product_info['quantity'] <= 0) {
				//$this->data['stock'] = $product_info['stock'];
                $this->data['stock'] = 0;
			} else {
                /*
				if ($this->config->get('config_stock_display')) {
					$this->data['stock'] = $product_info['quantity'];
				} else {
					$this->data['stock'] = $this->language->get('text_instock');
				}
                */
                $this->data['stock'] = $product_info['quantity'];
			}
			
			if ($product_info['minimum']) {
				$this->data['minimum'] = $product_info['minimum'];
			} else {
				$this->data['minimum'] = 1;
			}
			
            $this->data['sku'] = $product_info['sku'];
			$this->data['model'] = $product_info['model'];
			$this->data['manufacturer'] = $product_info['manufacturer'];
			$this->data['manufacturers'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/manufacturer&manufacturer_id=' . $product_info['manufacturer_id']);
			$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
			$this->data['product_id'] = $this->request->get['product_id'];
			$this->data['average'] = $average;
			$this->data['full']	= HTTPS_IMAGE . $image;
			$this->data['options'] = array();
			
			$options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
			
			foreach ($options as $option) { 
				$option_value_data = array();
				
				foreach ($option['option_value'] as $option_value) {   
                    if($option_value['quantity'] > 0){
                        $option_price = (float)$option_value['price'] ? $this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')) : 0;                    
                        if($option_price && ($option_value['prefix'] == '-')){
                            $option_price = -1 * $option_price;                        
                        }
					    
                        $option_value_data[] = array(
						    'option_value_id' => $option_value['product_option_value_id'],
						    'name'            => $option_value['name'],
						    //'price'           => (float)$option_value['price'] ? $this->currency->formatPrice($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : FALSE,
                            'price'           => $option_price,
						    'prefix'          => $option_value['prefix'],    
                            'option_number'   => $option_value['product_option_number'] ? $option_value['product_option_number'] : $this->data['sku'],                     
                            'quantity'        => $option_value['quantity'],
					    );
                    }
				}
				
				$this->data['options'][] = array(
					'option_id'    => $option['product_option_id'],
					'name'         => $option['name'],
					'option_value' => $option_value_data,
                    'is_size'      => mb_stristr(trim($option['name']), 'størrelse', false, 'UTF-8'),
				);                
			}
			
			$this->data['size'] = $this->model_catalog_product->getSizeOption($this->data['options']);
			$this->data['size_guide'] = $product_info['size_guide'];
            $size_guide_data = new Template();
            $size_guide_data->data['size_guide'] = $this->data['size_guide'];  
            $size_guide_data->data['template'] = $this->config->get('config_template');             
            $this->data['size_guide_data'] = $size_guide_data->fetch($this->config->get('config_template') . '/template/product/size_guide.tpl'); 
            
            $this->load->model('setting/tooltip');              
            $this->data['size_hint'] = $this->model_setting_tooltip->getSizeHint();
			$this->data['shipping_note'] = $this->model_setting_tooltip->getShippingNote();
            
            $this->data['download_link'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'download/');
            
            //$full_image = ($image == 'no_image.jpg') ? $this->model_tool_image->resize($image, 291, 385) : HTTPS_IMAGE . $image; 
			$this->data['images'] = array(
				array(
					'full'	 => HTTPS_IMAGE . $image, 					
                    //'full'      => $full_image,
					'popup'     => $this->model_tool_image->resize($image, 291, 385),					
					//'thumb'     => $this->model_tool_image->resize($image, 70, 78),
                    'thumb' => $this->model_tool_image->resize($image, 285, 346),
				),					
			);
			
			$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
			
			foreach ($results as $result) {
				$this->data['images'][] = array(
					'full'	 => HTTPS_IMAGE . $result['image'],
					'popup' => $this->model_tool_image->resize($result['image'], 291, 385),
					//'thumb' => $this->model_tool_image->resize($result['image'], 70, 78)
                    'thumb' => $this->model_tool_image->resize($result['image'], 285, 346),
					//'popup' => $this->model_tool_image->resize($result['image'] , $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
					//'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')),                   
				);
			}

			//Addwish + Canonical link
			$this->document->links = array();	
			$this->document->links[] = array(
				'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $this->request->get['product_id']),
				'rel'  => 'canonical'
			);
			$this->document->links[] = array(
				'href'	=> '<meta property="og:title" content="'.$product_info['name'].'"/>',
				'rel'	=> 'addwish_meta_tags',
			);
			$this->document->links[] = array(
				'href'	=> '<meta property="og:image" content="'.$this->data['thumb'].'"/>',
				'rel'	=> 'addwish_meta_tags',
			);
			$this->document->links[] = array(
				'href'	=> '<meta property="og:price" content="'.$this->data['price'].'"/>',
				'rel'	=> 'addwish_meta_tags',
			);
			
			$this->data['colors'] = array();
            $this->data['colors_option_id'] = 0;
            /*
			$results = $this->model_catalog_product->getProductColors($this->request->get['product_id']);
			reset($results);
			$option = current($results);
			$this->data['colors_option_id'] = $option['option_id'];	
					
			foreach ($results as $result) {
				$color_data = $this->model_catalog_product->getProductColorImages($this->request->get['product_id'], $result['product_color_id']);
				if($color_data){
					$color_images = array();
					foreach ($color_data as $color) {
						$color_images[] = array(
							'full'	 			=> HTTPS_IMAGE . $color['image'],		
							'popup' 			=> $this->model_tool_image->resize($color['image'], 291, 385),			
							'thumb' 			=> $this->model_tool_image->resize($color['image'], 70, 78),
						);	
					}
					
					$this->data['colors'][] = array(
						'full'	 			=> HTTPS_IMAGE . $result['image'],		
						'popup' 			=> $this->model_tool_image->resize($result['image'], 291, 385),			
						'thumb' 			=> $this->model_tool_image->resizeNoScale($result['color_image'], 43, 11),
						'color_id'			=> $result['product_color_id'],
						'option_id'			=> $result['option_id'],
						'option_value'		=> $result['option_value_id'],	
						'image_list'		=> $color_images,	
					);	
				}			
			}			
			*/
			if(isset($this->request->get['color_id'])) {
				$this->data['current_color'] = $this->request->get['color_id'];             
			}
			else{
				$this->data['current_color'] = 0;
			}
					
            $this->data['video'] = false; //$product_info['video'] ? HTTPS_IMAGE . $product_info['video'] : '';
			$this->data['youtube_video'] = trim($product_info['youtube_video']) ? $product_info['youtube_video'] : '';
			$this->data['youtube_video_width'] = (int)$product_info['youtube_video_width'] ? $product_info['youtube_video_width'] : 300;
			$this->data['youtube_video_height'] = (int)$product_info['youtube_video_height'] ? $product_info['youtube_video_height'] : 315;
            $this->data['video_thumb'] = $this->model_tool_image->resize('flv_icon.png', 70, 78); 
            $this->data['text_video_thumb'] = $this->language->get('text_video_thumb');  
            
            $length_class = $this->model_catalog_product->getProductLengthClass($product_info['length_class_id']);
            $this->data['length'] = number_format($product_info['length']); 
            $this->data['width'] = number_format($product_info['width']); 
            $this->data['height'] = number_format($product_info['height']); 
            $this->data['length_class'] = $length_class;
            
            $weight_class = $this->model_catalog_product->getProductWeightClass($product_info['weight_class_id']);
            $this->data['weight'] = number_format($product_info['weight']); 
            $this->data['weight_class'] = $weight_class;
			            
            $this->data['product_number'] = $product_info['product_number'];
			$this->data['delay_delivery'] = $product_info['delay_delivery'];
            
            /*
            $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
            if(!empty($manufacturer_info)){
                $this->data['manufacturer_desc'] = html_entity_decode($manufacturer_info['description'], ENT_QUOTES, 'UTF-8');
            }
            else{
                $this->data['manufacturer_desc'] = '';
            }
            */
            $this->data['manufacturer_desc'] = html_entity_decode($product_info['manufacturer_desc'], ENT_QUOTES, 'UTF-8');
            
			$this->data['products'] = array();			
			$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);			
			foreach ($results as $result) {
				if ($result['image']) {
					$image = $result['image'];
				} else {
					$image = 'no_image.jpg';
				}
			
				if ($this->config->get('config_review')) {
					$rating = $this->model_catalog_review->getAverageRating($result['product_id']);	
				} else {
					$rating = false;
				}
				
				$price = $this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'));
				$price_formatted = $this->currency->formatPrice($price);
				$discount = 0;
				$discount_fomatted = 0;
				$discount_data = $this->model_catalog_discount->getDiscount($result['product_id']);
				if($discount_data > 0){
					$discount = $discount_data;
					$discount_fomatted =$this->currency->formatPrice($this->tax->calculate($discount_data, $result['tax_class_id'], $this->config->get('config_tax')));
				}
				
				$discounts_data = $this->model_catalog_product->getProductDiscounts($result['product_id']);
				if($discounts_data){
					$discount = $discounts_data[0]['price'];
					$discount_fomatted = $this->currency->formatPrice($this->tax->calculate($discounts_data[0]['price'], $result['tax_class_id'], $this->config->get('config_tax')));
				}
				$discounts = array();
				foreach ($discounts_data as $discount_data) {
					$discounts[] = array(
							'quantity' => $discount_data['quantity'],
							'price'    => $this->currency->formatPrice($this->tax->calculate($discount_data['price'], $result['tax_class_id'], $this->config->get('config_tax')))
					);
				}
				
				$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
				if ($special) {
					$this->data['special'] = $this->currency->formatPrice($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
				} else {
					$this->data['special'] = FALSE;
				}
				 
				$attribute_price = 0;
				$min_price = false;
				$price_ref = $discount ? $discount : $price;
				//$options = $this->model_catalog_product->getProductOptions($result['product_id']);
				$options = $this->model_catalog_product->getActiveProductOptions($result['product_id']);
				foreach($options as $option_item){
					foreach($option_item['option_value'] as $option_value){
						$option_price = (float)$option_value['price'] ? $this->tax->calculate($option_value['price'], $result['tax_class_id'], $this->config->get('config_tax')) : 0;
						if($option_price && ($option_value['prefix'] == '-')){
							$option_price = -1 * $option_price;
						}
				
						if($option_price < $attribute_price){
							$attribute_price = $option_price;
						}
				
						if($option_price > 0){
							$min_price = true;
						}
					}
				}
				 
				$add = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']);
					
				$colors = array();
				
				$rate_discount = ((floatval($price) - floatval($price_ref)) / floatval($price)) * 100;
				
				$rate_discount = round($rate_discount);
					
				if($attribute_price != 0){
					$ref_price =  $this->currency->formatPrice($price_ref + $attribute_price);
				}
				elseif($min_price){
					$ref_price = $this->currency->formatPrice($price_ref);
				}
				else{
					$ref_price = 0;
				}
				
				
				
				//$shortname = (strlen($result['name']) <= 16) ? $result['name'] : substr($result['name'], 0 ,16) . ' ...';
				$shortname = $this->model_catalog_product->breakProductName($result['name'], 34);
								
                $related_path = $this->model_catalog_product->getCategoriesPath($result['product_id']);
               
				$this->data['products'][] = array(
						'name'      => $result['name'],
						'product_id'=> $result['product_id'],
						'shortname' => $shortname,
						'thumb'     => $this->model_tool_image->resize($image, 155, 193),
						'price'     => $price_formatted,
						'ref_price' => $ref_price,
						'discount'  => $discount_fomatted,
						'discounts' => $discounts,
						'options'   => $options,
						'special'   => $special,
						'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&path=' . $related_path . '&product_id=' . $result['product_id']),
						'add'	    => $add,
						'rate_discount' => $rate_discount,
						'colors'	=> $colors,
						'unbreak'   => mb_strlen($shortname, 'UTF-8') < 34,
				);
			}

			if (!$this->config->get('config_customer_price')) {
				$this->data['display_price'] = TRUE;
			} elseif ($this->customer->isLogged()) {
				$this->data['display_price'] = TRUE;

			} else {
				$this->data['display_price'] = FALSE;
			}
			
            $url = HTTP_SERVER . 'index.php?route=product/' . ($path ? 'category' . $path : 'categories');
            $this->data['back'] = $this->model_tool_seo_url->rewrite($url);     
            $this->data['product_category'] = $path;                          
            $back_path = ($path ? $path : '') . '&product_id=' . $this->request->get['product_id'];             
            $this->session->data['go_back_product'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path;            
            $this->session->data['go_back_category'] = HTTP_SERVER . 'index.php?route=product/category' . $path;		
			$this->data['product_link'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path;
			$this->data['normal_view'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path;
            $this->data['zoom_view'] = HTTP_SERVER . 'index.php?route=product/product/zoom' . $back_path;
            
			$this->model_catalog_product->updateViewed($this->request->get['product_id']); 			
			$this->data['tags'] = array();          					
			$results = $this->model_catalog_product->getProductTags($this->request->get['product_id']);
			
            $this->data['breadcrumbs'] = $this->document->breadcrumbs;
            $this->data['allow_stock_checkout'] = !$this->config->get('config_stock_checkout') && false;            
			
			foreach ($results as $result) {
				if ($result['tag']) {
					$this->data['tags'][] = array(
						'tag'	=> $result['tag'],
						'href'	=> HTTP_SERVER . 'index.php?route=product/search&keyword=' . $result['tag']
					);
				}
			}
			
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product_new.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/product/product_new.tpl';
			} else {
				$this->template = 'default/template/product/product_new.tpl';
			}
			
			$this->children = array(
				'common/header',                
                'common/footer',
                'common/column_left',                
                'module/tellfriend',
                'module/send_question',
				'module/services',
					'module/newsletter'
			);
			
			$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
		} else {
			$url = '';  			
			if (isset($this->request->get['path'])) {
				$url .= '&path=' . $this->request->get['path'];
			}
			
			if (isset($this->request->get['manufacturer_id'])) {
				$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
			}			

			if (isset($this->request->get['keyword'])) {
				$url .= '&keyword=' . $this->request->get['keyword'];
			}			

			if (isset($this->request->get['category_id'])) {
				$url .= '&category_id=' . $this->request->get['category_id'];
			}
				
			if (isset($this->request->get['description'])) {
				$url .= '&description=' . $this->request->get['description'];
			}		
					
      		$this->document->breadcrumbs[] = array(
        		'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $product_id),
        		'text'      => $this->language->get('text_error'),
        		'separator' => $this->language->get('text_separator')
      		);			
		
      		$this->document->title = $this->language->get('text_error');

      		$this->data['heading_title'] = $this->language->get('text_error');

      		$this->data['text_error'] = $this->language->get('text_error');

      		$this->data['button_continue'] = $this->language->get('button_continue');

      		$this->data['continue'] = null; //HTTP_SERVER . 'index.php?route=common/home';
            $this->data['back'] = HTTP_SERVER . 'index.php?route=product/product';
	  
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}
			
			$this->children = array(
				'common/header',				
				'common/footer',
                'common/column_left',				
			);
			
			$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
    	}
  	}
	
	public function review() {
    	$this->language->load('product/product');
		
		$this->load->model('catalog/review');

		$this->data['text_no_reviews'] = $this->language->get('text_no_reviews');

		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}  
		
		$this->data['reviews'] = array();
			
		$results = $this->model_catalog_review->getReviewsByProductId($this->request->get['product_id'], ($page - 1) * 5, 5);
      		
		foreach ($results as $result) {
        	$this->data['reviews'][] = array(
        		'author'     => $result['author'],
				'rating'     => $result['rating'],
				'text'       => strip_tags($result['text']),
        		'stars'      => sprintf($this->language->get('text_stars'), $result['rating']),
        		'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
        	);
      	}			
		
		$review_total = $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']);
			
		$pagination = new Pagination();
		$pagination->total = $review_total;
		$pagination->page = $page;
		$pagination->limit = 5; 
		$pagination->text = $this->language->get('text_pagination');
		$pagination->url = HTTP_SERVER . 'index.php?route=product/product/review&product_id=' . $this->request->get['product_id'] . '&page={page}';
			
		$this->data['pagination'] = $pagination->render();

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/review.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/product/review.tpl';
		} else {
			$this->template = 'default/template/product/review.tpl';
		}
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
	}
	
	public function write() {
		$this->language->load('product/product');
		
		$this->load->model('catalog/review');
		
		$json = array();
		
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
			$this->model_catalog_review->addReview($this->request->get['product_id'], $this->request->post);
			
			$json['success'] = $this->language->get('text_success');
		} else {
			$json['error'] = $this->error['message'];
		}	
		
		$this->load->library('json');
		
		$this->response->setOutput(Json::encode($json));
	}
	
	public function captcha() {
		$this->load->library('captcha');
		
		$captcha = new Captcha();
		
		$this->session->data['captcha'] = $captcha->getCode();
		
		$captcha->showImage();
	}
	
	private function validate() {
		if ((strlen(utf8_decode($this->request->post['name'])) < 3) || (strlen(utf8_decode($this->request->post['name'])) > 25)) {
			$this->error['message'] = $this->language->get('error_name');
		}
		
		if ((strlen(utf8_decode($this->request->post['text'])) < 25) || (strlen(utf8_decode($this->request->post['text'])) > 1000)) {
			$this->error['message'] = $this->language->get('error_text');
		}

		if (!$this->request->post['rating']) {
			$this->error['message'] = $this->language->get('error_rating');
		}

		if (!isset($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
			$this->error['message'] = $this->language->get('error_captcha');
		}

		if (!$this->error) {
			return TRUE;
		} else {
			return FALSE;
		}	
	}
	
	public function addSuccess() {
		$this->load->model('catalog/product');
		$this->load->model('tool/seo_url');
		
		if (isset($this->request->get['product_id'])) {
			$product_id = $this->request->get['product_id'];
		} 
		else {
			$product_id = 0;
		}
		$product_info = $this->model_catalog_product->getProduct($product_id);
		
		$path = '';
		if (isset($this->request->get['path'])) {
            $path .= '&path=' . $this->request->get['path'];
		}
		
		$this->data['template'] = $this->config->get('config_template'); 
		$this->data['checkout'] = HTTP_SERVER . 'index.php?route=checkout/cart';  
		$this->data['next_step'] = HTTP_SERVER . 'index.php?route=checkout/cart';  
		$url = HTTP_SERVER . 'index.php?route=product/product' . $path . '&product_id=' . $product_info['product_id'];
        $this->data['back'] = $this->model_tool_seo_url->rewrite($url);     
        $this->data['product_category'] = $path;
        $back_path = ($path ? $path : '') . '&product_id=' . $this->request->get['product_id'];             
        $this->session->data['go_back_product'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path;
        $this->session->data['go_back_category'] = HTTP_SERVER . 'index.php?route=product/category' . $path;
            
        $this->document->title = 'Produkter'; 
		$this->data['heading_title'] = '';
		$this->data['sku'] = '';   
		$this->data['price'] = '';
		if ($product_info) {
			$this->document->title = $product_info['name']; 
			$this->data['heading_title'] = $product_info['name'];   
			$this->data['sku'] = $product_info['sku'];  
			$this->data['price'] = $this->currency->formatPrice($product_info['price']);
		}
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product_success.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/product/product_success.tpl';
		} else {
			$this->template = 'default/template/product/product_success.tpl';
		}
		
		$this->children = array(
			'common/header',                
            'common/footer',
            'common/column_left',
		);
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
	}
    
    public function zoom(){
        $this->language->load('product/product');                  
        
        $this->load->model('tool/seo_url');            
        $this->load->model('catalog/category');  
        $this->document->breadcrumbs = array();
               
        if (isset($this->request->get['path'])) {
            $path = '';                        
            foreach (explode('_', $this->request->get['path']) as $path_id) {
                $category_info = $this->model_catalog_category->getCategory($path_id);
                
                if (!$path) {
                    $path = $path_id;
                } else {
                    $path .= '_' . $path_id;
                }
                
                /*
                if ($category_info) {
                    $this->document->breadcrumbs[] = array(
                        'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $path),
                        'text'      => $category_info['name'],
                        'separator' => $this->language->get('text_separator')
                    );
                }
                */
            }
            
            $categories_list = explode('_', $this->request->get['path']);
            $this->document->breadcrumbs = $this->model_catalog_category->createBreadcrumbs($categories_list);
            /*
            $breadcrumbs = explode('_', $this->request->get['path']);
            $breadcrumb_path = '';
            foreach($breadcrumbs as $breadcrumb){
                $separator = $breadcrumb_path ? ' >> '  : false;
                $breadcrumb_path = $breadcrumb_path ? ($breadcrumb_path . '_' . $breadcrumb) : $breadcrumb;
                
                $this->document->breadcrumbs[] = array(
                    'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/categories&path=' . $breadcrumb_path),
                    'text'      => $this->model_catalog_category->getCategoryName($breadcrumb),
                    'separator' => $separator,
                );
            } 
            */          
        }        
        
        $this->data['template'] = $this->config->get('config_template');          
        
        $this->load->model('catalog/product');
        
        if (isset($this->request->get['product_id'])) {
            $product_id = $this->request->get['product_id'];
        } else {
            $product_id = 0;
        }
        
        $product_info = $this->model_catalog_product->getProduct($product_id);
        
        if ($product_info) {
            $url = '';
            $path = '';
            if (isset($this->request->get['path'])) {
                $url .= '&path=' . $this->request->get['path'];
                $path .= '&path=' . $this->request->get['path'];
            }               
            
            $this->document->breadcrumbs[] = array(
                'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $this->request->get['product_id']),
                'text'      => $product_info['name'],
                //'separator' => $this->language->get('text_separator')
                'separator' => ' >> ',
            );            
            
            $this->document->title = $product_info['name'];            
            $this->document->keywords = $product_info['meta_keywords'];            
            $this->document->description = $product_info['meta_description'];
         
            $this->data['heading_title'] = $product_info['name'];
            //$shortname = (strlen($product_info['name']) < 61) ? $product_info['name'] : substr($product_info['name'], 0 ,61) . ' ...';                         
            //$shortname = $this->model_catalog_product->breakProductName($product_info['name'], 57); 
            $shortname = $this->model_catalog_product->productShortName($product_info['name'], 57); 
            $this->data['short_title'] = $shortname; 
            
            $this->data['text_enlarge'] = $this->language->get('text_enlarge');
            $this->data['text_discount'] = $this->language->get('text_discount');
            $this->data['text_options'] = $this->language->get('text_options');
            $this->data['text_price'] = $this->language->get('text_price');
            $this->data['text_availability'] = $this->language->get('text_availability');
            $this->data['text_model'] = $this->language->get('text_model');
            $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
            $this->data['text_order_quantity'] = $this->language->get('text_order_quantity');
            $this->data['text_price_per_item'] = $this->language->get('text_price_per_item');
            $this->data['text_qty'] = $this->language->get('text_qty');
            $this->data['text_write'] = $this->language->get('text_write');
            $this->data['text_average'] = $this->language->get('text_average');
            $this->data['text_no_rating'] = $this->language->get('text_no_rating');
            $this->data['text_note'] = $this->language->get('text_note');
            $this->data['text_no_images'] = $this->language->get('text_no_images');
            $this->data['text_no_related'] = $this->language->get('text_no_related');
            $this->data['text_wait'] = $this->language->get('text_wait');
            $this->data['text_tags'] = $this->language->get('text_tags');
            $this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);

            $this->data['entry_name'] = $this->language->get('entry_name');
            $this->data['entry_review'] = $this->language->get('entry_review');
            $this->data['entry_rating'] = $this->language->get('entry_rating');
            $this->data['entry_good'] = $this->language->get('entry_good');
            $this->data['entry_bad'] = $this->language->get('entry_bad');
            $this->data['entry_captcha'] = $this->language->get('entry_captcha');

            $this->data['button_continue'] = $this->language->get('button_continue');  
            $this->data['tab_description'] = $this->language->get('tab_description');             
            $this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');

            $this->data['action'] = HTTP_SERVER . 'index.php?route=checkout/cart';
            $this->data['checkout'] = HTTP_SERVER . 'index.php?route=checkout/cart';
            $this->data['redirect'] = HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $this->request->get['product_id'];
            $this->data['success_url'] = HTTP_SERVER . 'index.php?route=product/product/addsuccess' . $path . '&product_id=' . $product_info['product_id'];
            $this->data['next_step'] = HTTP_SERVER . 'index.php?route=checkout/cart'; 
            $this->data['forhandle'] = HTTP_SERVER . 'index.php?route=information/forhandlen';
            
            $this->load->model('tool/image');

            if ($product_info['image']) {
                $image = $product_info['image'];
            } else {
                $image = 'no_image.jpg'; 
            }    
                    
            $this->data['popup'] = $this->model_tool_image->resize($image, $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
            //$this->data['thumb'] = $this->model_tool_image->resize($image, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
            $this->data['thumb'] = $this->model_tool_image->resize($image, 220, 316);

            $this->data['product_info'] = $product_info;
            
            $discount = $this->model_catalog_product->getProductDiscount($this->request->get['product_id']);
            
            if ($discount) {
                $this->data['price'] = $this->currency->formatPrice($this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax')));
                
                $this->data['special'] = FALSE;
            } else {
                $this->data['price'] = $this->currency->formatPrice($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
            
                $special = $this->model_catalog_product->getProductSpecial($this->request->get['product_id']);
            
                if ($special) {
                    $this->data['special'] = $this->currency->formatPrice($this->tax->calculate($special, $product_info['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    $this->data['special'] = FALSE;
                }
            }
            
            $discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
            
            $this->data['discounts'] = array(); 
            
            foreach ($discounts as $discount) {
                $this->data['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->formatPrice($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
                );
            }
            
            if ($product_info['quantity'] <= 0) {
                $this->data['stock'] = $product_info['stock'];
            } else {
                if ($this->config->get('config_stock_display')) {
                    $this->data['stock'] = $product_info['quantity'];
                } else {
                    $this->data['stock'] = $this->language->get('text_instock');
                }
            }
            
            if ($product_info['minimum']) {
                $this->data['minimum'] = $product_info['minimum'];
            } else {
                $this->data['minimum'] = 1;
            }
            
            $this->data['sku'] = $product_info['sku'];
            $this->data['model'] = $product_info['model'];
            $this->data['manufacturer'] = $product_info['manufacturer'];
            $this->data['manufacturers'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/manufacturer&manufacturer_id=' . $product_info['manufacturer_id']);
            $this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
            $this->data['product_id'] = $this->request->get['product_id'];
            $this->data['full']    = HTTPS_IMAGE . $image;
            $this->data['options'] = array();
            $this->data['product_number'] = $product_info['product_number'];
            
            $options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
            
            foreach ($options as $option) { 
                $option_value_data = array();
                
                foreach ($option['option_value'] as $option_value) {
                    $option_value_data[] = array(
                        'option_value_id' => $option_value['product_option_value_id'],
                        'name'            => $option_value['name'],
                        'price'           => (float)$option_value['price'] ? $this->currency->formatPrice($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : FALSE,
                        'prefix'          => $option_value['prefix'],
                        'option_number'   => $option_value['product_option_number']
                    );
                }
                
                $this->data['options'][] = array(
                    'option_id'    => $option['product_option_id'],
                    'name'         => $option['name'],
                    'option_value' => $option_value_data
                );
            }
            
            $this->data['size'] = $this->model_catalog_product->getSizeOption($this->data['options']);
            $this->data['size_guide'] = $product_info['size_guide'];
            $size_guide_data = new Template();
            $size_guide_data->data['size_guide'] = $this->data['size_guide'];  
            $size_guide_data->data['template'] = $this->config->get('config_template');             
            $this->data['size_guide_data'] = $size_guide_data->fetch($this->config->get('config_template') . '/template/product/size_guide.tpl'); 
            
            //$full_image = ($image == 'no_image.jpg') ? $this->model_tool_image->resize($image, 291, 385) : HTTPS_IMAGE . $image; 
            $this->data['images'] = array(
                array(
                    'full'     => HTTPS_IMAGE . $image,                     
                    //'full'      => $full_image,                     
                    'popup'     => $this->model_tool_image->resize($image, 291, 385),                    
                    'thumb'     => $this->model_tool_image->resize($image, 35, 39),  
                ),                    
            );
            $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);            
            foreach ($results as $result) {
                $this->data['images'][] = array(
                    'full'     => HTTPS_IMAGE . $result['image'],
                    'popup' => $this->model_tool_image->resize($result['image'], 291, 385),
                    'thumb' => $this->model_tool_image->resize($result['image'], 35, 39)                    
                );
            }

        	if(isset($this->request->get['color_id'])) {
				$this->data['current_color'] = $this->request->get['color_id']; 
				$current_color = '&color_id=' . $this->data['current_color'];           
			}
			else{
				$this->data['current_color'] = 0;
				$current_color = '';
			}
			
        	$result = $this->model_catalog_product->getProductColorById($this->request->get['product_id'], $this->data['current_color']);
        	if($result){        		
	        	$color_data = $this->model_catalog_product->getProductColorImages($this->request->get['product_id'], $result['product_color_id']);
	        	if($color_data){
					$color_images = array();
					foreach ($color_data as $color) {
						$color_images[] = array(
							'full'	 			=> HTTPS_IMAGE . $color['image'],		
							'popup' 			=> $this->model_tool_image->resize($color['image'], 291, 385),			
							'thumb' 			=> $this->model_tool_image->resize($color['image'], 35, 39),
						);	
					}	
					/*		
					$this->data['color_images'] = array(
						'full'	 			=> HTTPS_IMAGE . $result['image'],		
						'popup' 			=> $this->model_tool_image->resize($result['image'], 291, 385),			
						'thumb' 			=> $this->model_tool_image->resizeNoScale($result['color_image'], 43, 11),
						'color_id'			=> $result['product_color_id'],
						'option_id'			=> $result['option_id'],
						'option_value'		=> $result['option_value_id'],	
						'image_list'		=> $color_images,	
					);	
					*/				
	
					$this->data['full']  	= HTTPS_IMAGE . $result['image'];
		            $this->data['popup'] 	= $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));	            
		            $this->data['thumb'] 	= $this->model_tool_image->resize($result['image'], 220, 316);
		            $this->data['images'] 	= $color_images;
	        	}
        	}
			
            /*
            $this->load->model('catalog/manufacturer');  
            $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
            if(!empty($manufacturer_info)){
                $this->data['manufacturer_desc'] = html_entity_decode($manufacturer_info['description'], ENT_QUOTES, 'UTF-8');
            }
            else{
                $this->data['manufacturer_desc'] = '';
            }
            */
            $this->data['manufacturer_desc'] = html_entity_decode($product_info['manufacturer_desc'], ENT_QUOTES, 'UTF-8');  
            
            $this->data['products'] = array();               
            $results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);                
            foreach ($results as $result) {
                if ($result['image']) {
                    $image = $result['image'];
                } else {
                    $image = 'no_image.jpg';
                }
            
                if ($this->config->get('config_review')) {
                    $rating = $this->model_catalog_review->getAverageRating($result['product_id']);    
                } else {
                    $rating = false;
                }
                
                $special = FALSE;
                
                $discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
            
                if ($discount) {
                    $price = $this->currency->formatPrice($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    $price = $this->currency->formatPrice($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
                    
                    $special = $this->model_catalog_product->getProductSpecial($result['product_id']);
                
                    if ($special) {
                        $special = $this->currency->formatPrice($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
                    }
                }
            
                $options = $this->model_catalog_product->getProductOptions($result['product_id']);
            
                if ($options) {
                    $add = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']);
                } else {
                    //$add = HTTPS_SERVER . 'index.php?route=checkout/cart&product_id=' . $result['product_id'];
                    $add = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']);
                }
            
                $related_path = $this->model_catalog_product->getCategoriesPath($result['product_id']); 
                
                $this->data['products'][] = array(
                    'product_id'    => $result['product_id'],
                    'name'            => $result['name'],
                    'model'           => $result['model'],
                    'rating'          => $rating,
                    'stars'           => sprintf($this->language->get('text_stars'), $rating),
                    'price'           => $price,
                    'options'         => $options,
                    'special'         => $special,
                    'full'            => HTTPS_IMAGE . $image,
                    'image'           => $this->model_tool_image->resize($image, 61, 75),
                    //'thumb'           => $this->model_tool_image->resize($image, $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height')),                    
                    'href'            => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&path=' . $related_path . '&product_id=' . $result['product_id']),
                    'add'            => $add
                );
            }
                      
            if (!$this->config->get('config_customer_price')) {
                $this->data['display_price'] = TRUE;
            } elseif ($this->customer->isLogged()) {
                $this->data['display_price'] = TRUE;

            } else {
                $this->data['display_price'] = FALSE;
            }
            
			$this->document->links = array();    
            $this->document->links[] = array(
                'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $this->request->get['product_id']),
                'rel'  => 'canonical'
            );
			$this->document->links[] = array(
				'href'	=> '<meta property="og:title" content="'.$product_info['name'].'"/>',
				'rel'	=> 'addwish_meta_tags',
			);
			$this->document->links[] = array(
				'href'	=> '<meta property="og:image" content="'.$this->data['thumb'].'"/>',
				'rel'	=> 'addwish_meta_tags',
			);
			$this->document->links[] = array(
				'href'	=> '<meta property="og:price" content="'.$this->data['price'].'"/>',
				'rel'	=> 'addwish_meta_tags',
			);
			
            $url = HTTP_SERVER . 'index.php?route=product/' . ($path ? 'category' . $path : 'categories');
            $this->data['back'] = $this->model_tool_seo_url->rewrite($url);     
            $this->data['product_category'] = $path;                          
            $back_path = ($path ? $path : '') . '&product_id=' . $this->request->get['product_id'];             
            $this->session->data['go_back_product'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path;            
            $this->session->data['go_back_category'] = HTTP_SERVER . 'index.php?route=product/category' . $path;        
            $this->data['product_link'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path;
            $this->data['normal_view'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path . $current_color;
            $this->data['zoom_view'] = HTTP_SERVER . 'index.php?route=product/product/zoom' . $back_path;
            
            $this->model_catalog_product->updateViewed($this->request->get['product_id']);             
            $this->data['tags'] = array();                              
            $results = $this->model_catalog_product->getProductTags($this->request->get['product_id']);
            
            foreach ($results as $result) {
                if ($result['tag']) {
                    $this->data['tags'][] = array(
                        'tag'    => $result['tag'],
                        'href'    => HTTP_SERVER . 'index.php?route=product/search&keyword=' . $result['tag']
                    );
                }
            }
            
            $this->data['breadcrumbs'] = $this->document->breadcrumbs;
            $this->language->load('common/footer');        
            $this->data['text_powered_by'] = sprintf($this->language->get('text_powered_by'), date('Y', time()));
            
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product_zoom.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/product/product_zoom.tpl';
            } else {
                $this->template = 'default/template/product/product.tpl';
            }
            
            $this->children = array(
                'common/header',                
                'common/footer',
                'common/column_left',                
                'module/cart_detailview',
            	'module/services'
            );
            
            $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
        } else {
            $url = '';              
            if (isset($this->request->get['path'])) {
                $url .= '&path=' . $this->request->get['path'];
            }
            
            if (isset($this->request->get['manufacturer_id'])) {
                $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
            }            

            if (isset($this->request->get['keyword'])) {
                $url .= '&keyword=' . $this->request->get['keyword'];
            }            

            if (isset($this->request->get['category_id'])) {
                $url .= '&category_id=' . $this->request->get['category_id'];
            }
                
            if (isset($this->request->get['description'])) {
                $url .= '&description=' . $this->request->get['description'];
            } 
            /*        
            $this->document->breadcrumbs[] = array(
                'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $product_id),
                'text'      => $this->language->get('text_error'),
                'separator' => $this->language->get('text_separator')
            );            
            */
            $this->document->title = $this->language->get('text_error');

            $this->data['heading_title'] = $this->language->get('text_error');

            $this->data['text_error'] = $this->language->get('text_error');

            $this->data['button_continue'] = $this->language->get('button_continue');

            $this->data['continue'] = null; //HTTP_SERVER . 'index.php?route=common/home';
            $this->data['back'] = HTTP_SERVER . 'index.php?route=product/product';               
            
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
            } else {
                $this->template = 'default/template/error/not_found.tpl';
            }
            
            $this->children = array(
                'common/header',                
                'common/footer',
                'common/column_left',                
            );
            
            $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
        }   
    }
    
    function productpopup(){
    	$this->language->load('product/product');     				
		$this->document->breadcrumbs = array();
        unset($this->session->data['in_stock']);

        /*
		$this->document->breadcrumbs[] = array(
			'href'      => HTTP_SERVER . 'index.php?route=common/home',
			'text'      => $this->language->get('text_home'),
			'separator' => FALSE
		);
		*/   
		$this->load->model('tool/seo_url');   		
		$this->load->model('catalog/category');			
        
		if (isset($this->request->get['path'])) {
			$path = '';
				
			foreach (explode('_', $this->request->get['path']) as $path_id) {
				$category_info = $this->model_catalog_category->getCategory($path_id);
				
				if (!$path) {
					$path = $path_id;
				} else {
					$path .= '_' . $path_id;
				}
				/*
				if ($category_info) {
					$this->document->breadcrumbs[] = array(
						'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $path),
						'text'      => $category_info['name'],
						'separator' => $this->language->get('text_separator')
					);
				}
                */
			}
            
            $categories_list = explode('_', $this->request->get['path']);
            $this->document->breadcrumbs = $this->model_catalog_category->createBreadcrumbs($categories_list);
            /*
            $breadcrumbs = explode('_', $this->request->get['path']);
            $breadcrumb_path = '';
            foreach($breadcrumbs as $breadcrumb){
                $separator = $breadcrumb_path ? ' >> '  : false;
                $breadcrumb_path = $breadcrumb_path ? ($breadcrumb_path . '_' . $breadcrumb) : $breadcrumb;
                
                $this->document->breadcrumbs[] = array(
                    'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/categories&path=' . $breadcrumb_path),
                    'text'      => $this->model_catalog_category->getCategoryName($breadcrumb),
                    'separator' => $separator,
                );
            }  
            */         
		}
		
		$this->load->model('catalog/manufacturer');			
		if (isset($this->request->get['manufacturer_id'])) {        
			$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);

            /*
			if ($manufacturer_info) {	
				$this->document->breadcrumbs[] = array(					
                    'href'        => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/manufacturer&viewManufacturer&manufacturer_id=' . $this->request->get['manufacturer_id']),
					'text'	    => $manufacturer_info['name'],
					'separator' => $this->language->get('text_separator')
				);
			}
            */
		}
        
		if (isset($this->request->get['keyword'])) {
			$url = '';

			if (isset($this->request->get['category_id'])) {
				$url .= '&category_id=' . $this->request->get['category_id'];
			}	
			
			if (isset($this->request->get['description'])) {
				$url .= '&description=' . $this->request->get['description'];
			}
			/*
			$this->document->breadcrumbs[] = array(
				'href'      => HTTP_SERVER . 'index.php?route=product/search&keyword=' . $this->request->get['keyword'] . $url,
				'text'      => $this->language->get('text_search'),
				'separator' => $this->language->get('text_separator')
			);
            */	
		}
        
		$this->data['template'] = $this->config->get('config_template');  
        
		$this->load->model('catalog/product');
		
		if (isset($this->request->get['product_id'])) {
			$product_id = $this->request->get['product_id'];
		} else {
			$product_id = 0;
		}
		
		
		
		$product_info = $this->model_catalog_product->getProduct($product_id);
		
		
		if ($product_info) {
			$url = '';
			$path = '';
			if (isset($this->request->get['path'])) {
				$url .= '&path=' . $this->request->get['path'];
                $path .= '&path=' . $this->request->get['path'];
			}
			
			if (isset($this->request->get['manufacturer_id'])) {
				$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
			}			

			if (isset($this->request->get['keyword'])) {
				$url .= '&keyword=' . $this->request->get['keyword'];
			}			

			if (isset($this->request->get['category_id'])) {
				$url .= '&category_id=' . $this->request->get['category_id'];
			}
				
			if (isset($this->request->get['description'])) {
				$url .= '&description=' . $this->request->get['description'];
			}				
									
			$this->document->breadcrumbs[] = array(
				'href'      => '', //$this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $this->request->get['product_id']),
				'text'      => $product_info['name'],
				//'separator' => $this->language->get('text_separator')
                'separator' => ' >> ',
			);			
			
			$this->document->title = $product_info['name'];			
			$this->document->keywords = $product_info['meta_keywords'];			
			$this->document->description = $product_info['meta_description'];			

			$this->data['heading_title'] = $product_info['name'];
            //$shortname = (strlen($product_info['name']) < 61) ? $product_info['name'] : substr($product_info['name'], 0 ,61) . ' ...';                         
            //$shortname = $this->model_catalog_product->breakProductName($product_info['name'], 57);
            //$shortname = $this->model_catalog_product->productShortName($product_info['name'], 57);
			$shortname = $product_info['name'];
            $this->data['short_title'] = $shortname; 

			$this->data['text_enlarge'] = $this->language->get('text_enlarge');
			$this->data['text_discount'] = $this->language->get('text_discount');
			$this->data['text_options'] = $this->language->get('text_options');
			$this->data['text_price'] = $this->language->get('text_price');
			$this->data['text_availability'] = $this->language->get('text_availability');
			$this->data['text_model'] = $this->language->get('text_model');
			$this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
			$this->data['text_order_quantity'] = $this->language->get('text_order_quantity');
			$this->data['text_price_per_item'] = $this->language->get('text_price_per_item');
			$this->data['text_qty'] = $this->language->get('text_qty');
			$this->data['text_write'] = $this->language->get('text_write');
			$this->data['text_average'] = $this->language->get('text_average');
			$this->data['text_no_rating'] = $this->language->get('text_no_rating');
			$this->data['text_note'] = $this->language->get('text_note');
			$this->data['text_no_images'] = $this->language->get('text_no_images');
			$this->data['text_no_related'] = $this->language->get('text_no_related');
			$this->data['text_wait'] = $this->language->get('text_wait');
			$this->data['text_tags'] = $this->language->get('text_tags');
			$this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);

			$this->data['entry_name'] = $this->language->get('entry_name');
			$this->data['entry_review'] = $this->language->get('entry_review');
			$this->data['entry_rating'] = $this->language->get('entry_rating');
			$this->data['entry_good'] = $this->language->get('entry_good');
			$this->data['entry_bad'] = $this->language->get('entry_bad');
			$this->data['entry_captcha'] = $this->language->get('entry_captcha');

			$this->data['button_continue'] = $this->language->get('button_continue');
			
			$this->load->model('catalog/review');

			$this->data['tab_description'] = $this->language->get('tab_description');
			$this->data['tab_image'] = $this->language->get('tab_image');
			$this->data['tab_review'] = sprintf($this->language->get('tab_review'), $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']));
			$this->data['tab_related'] = $this->language->get('tab_related');
			
			if ($this->config->get('config_review')) {
				$average = $this->model_catalog_review->getAverageRating($this->request->get['product_id']);	
			} else {
				$average = false;
			}
			
			$this->data['review_status'] = $this->config->get('config_review');
			
			$this->data['text_stars'] = sprintf($this->language->get('text_stars'), $average);
			
			$this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');

			$this->data['action'] = HTTP_SERVER . 'index.php?route=checkout/cart';
			$this->data['checkout'] = HTTP_SERVER . 'index.php?route=checkout/cart';
			$this->data['redirect'] = HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $this->request->get['product_id'];
			$this->data['success_url'] = HTTP_SERVER . 'index.php?route=product/product/addsuccess' . $path . '&product_id=' . $product_info['product_id'];
            $this->data['next_step'] = HTTP_SERVER . 'index.php?route=checkout/cart';
			$this->data['current_url'] = urldecode($this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $url . '&product_id=' . $product_info['product_id']));
            
			$this->load->model('tool/image');

			if ($product_info['image']) {
				$image = $product_info['image'];
			} else {
				$image = 'no_image.jpg';
			}	
					
			$this->data['popup'] = $this->model_tool_image->resize($image, $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
			//$this->data['thumb'] = $this->model_tool_image->resize($image, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
            //$this->data['thumb'] = $this->model_tool_image->resize($image, 220, 316);
            $this->data['thumb'] = $this->model_tool_image->resize($image, 285, 346);

			$this->data['product_info'] = $product_info;			    
             
            /*           
			$discount = $this->model_catalog_product->getProductDiscount($this->request->get['product_id']);			
			if ($discount) {
				$this->data['price'] = $this->currency->formatPrice($this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax')));
                $this->data['price_ref'] = $this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax'));
				
				$this->data['special'] = FALSE;
			} else {        
				$this->data['price'] = $this->currency->formatPrice($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
                $this->data['price_ref'] = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'));
			
				$special = $this->model_catalog_product->getProductSpecial($this->request->get['product_id']);
			
				if ($special) {
					$this->data['special'] = $this->currency->formatPrice($this->tax->calculate($special, $product_info['tax_class_id'], $this->config->get('config_tax')));
				} else {
					$this->data['special'] = FALSE;
				}
			}
			*/
            $this->data['price'] = $this->currency->formatPrice($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
            $this->data['price_ref'] = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'));
            $this->data['discount'] =  0;
            
            $p_price = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'));
            $p_discount = 0;
                
            $this->load->model('catalog/discount');
            $discount = $this->model_catalog_discount->getDiscount($this->request->get['product_id']);
            
            if($discount > 0){
                $this->data['discount'] = $this->currency->formatPrice($this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax'))); 
                $this->data['price_ref'] = $discount;
                $p_discount = $discount;
            }
            
            
            
			$discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']); 			
            if($discounts){
                $this->data['price_ref'] = $discounts[0]['price']; 
                $this->data['discount'] = $this->currency->formatPrice($this->tax->calculate($discounts[0]['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
                $p_discount = $discounts[0]['price'];
            }
            
			$this->data['discounts'] = array();   			
			foreach ($discounts as $discount) {
				$this->data['discounts'][] = array(
					'quantity' => $discount['quantity'],
					'price'    => $this->currency->formatPrice($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
				);
			}

			$this->data['save_price'] = $this->currency->formatPrice(($p_price - $p_discount));
			
			$rate_discount = ((floatval($p_price) - floatval($p_discount)) / floatval($p_price)) * 100;
				
			$rate_discount = round($rate_discount);
				
			$this->data['rate_discount'] = $rate_discount;
			
             
            $special = $this->model_catalog_product->getProductSpecial($this->request->get['product_id']);        
            if ($special) {
                $this->data['special'] = $this->currency->formatPrice($this->tax->calculate($special, $product_info['tax_class_id'], $this->config->get('config_tax')));
            } else {
                $this->data['special'] = FALSE;
            }
                 
			if ($product_info['quantity'] <= 0) {
				//$this->data['stock'] = $product_info['stock'];
                $this->data['stock'] = 0;
			} else {
                /*
				if ($this->config->get('config_stock_display')) {
					$this->data['stock'] = $product_info['quantity'];
				} else {
					$this->data['stock'] = $this->language->get('text_instock');
				}
                */
                $this->data['stock'] = $product_info['quantity'];
			}
			
			if ($product_info['minimum']) {
				$this->data['minimum'] = $product_info['minimum'];
			} else {
				$this->data['minimum'] = 1;
			}
			
            $this->data['sku'] = $product_info['sku'];
			$this->data['model'] = $product_info['model'];
			$this->data['manufacturer'] = $product_info['manufacturer'];
			$this->data['manufacturers'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/manufacturer&manufacturer_id=' . $product_info['manufacturer_id']);
			$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
			$this->data['product_id'] = $this->request->get['product_id'];
			$this->data['average'] = $average;
			$this->data['full']	= HTTPS_IMAGE . $image;
			$this->data['options'] = array();
			
			$options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
			
			foreach ($options as $option) { 
				$option_value_data = array();
				
				foreach ($option['option_value'] as $option_value) {   
                    if($option_value['quantity'] > 0){
                        $option_price = (float)$option_value['price'] ? $this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')) : 0;                    
                        if($option_price && ($option_value['prefix'] == '-')){
                            $option_price = -1 * $option_price;                        
                        }
					    
                        $option_value_data[] = array(
						    'option_value_id' => $option_value['product_option_value_id'],
						    'name'            => $option_value['name'],
						    //'price'           => (float)$option_value['price'] ? $this->currency->formatPrice($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : FALSE,
                            'price'           => $option_price,
						    'prefix'          => $option_value['prefix'],    
                            'option_number'   => $option_value['product_option_number'] ? $option_value['product_option_number'] : $this->data['sku'],                     
                            'quantity'        => $option_value['quantity'],
					    );
                    }
				}
				
				$this->data['options'][] = array(
					'option_id'    => $option['product_option_id'],
					'name'         => $option['name'],
					'option_value' => $option_value_data,
                    'is_size'      => mb_stristr(trim($option['name']), 'størrelse', false, 'UTF-8'),
				);                
			}
			
			$this->data['size'] = $this->model_catalog_product->getSizeOption($this->data['options']);
			$this->data['size_guide'] = $product_info['size_guide'];
            $size_guide_data = new Template();
            $size_guide_data->data['size_guide'] = $this->data['size_guide'];  
            $size_guide_data->data['template'] = $this->config->get('config_template');             
            $this->data['size_guide_data'] = $size_guide_data->fetch($this->config->get('config_template') . '/template/product/size_guide.tpl'); 
            
            $this->load->model('setting/tooltip');              
            $this->data['size_hint'] = $this->model_setting_tooltip->getSizeHint();
			$this->data['shipping_note'] = $this->model_setting_tooltip->getShippingNote();
            
            $this->data['download_link'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'download/');
            
            //$full_image = ($image == 'no_image.jpg') ? $this->model_tool_image->resize($image, 291, 385) : HTTPS_IMAGE . $image; 
			$this->data['images'] = array(
				array(
					'full'	 => HTTPS_IMAGE . $image, 					
                    //'full'      => $full_image,
					'popup'     => $this->model_tool_image->resize($image, 291, 385),					
					//'thumb'     => $this->model_tool_image->resize($image, 70, 78),
                    'thumb' => $this->model_tool_image->resize($image, 285, 346),
				),					
			);
			
			$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
			
			foreach ($results as $result) {
				$this->data['images'][] = array(
					'full'	 => HTTPS_IMAGE . $result['image'],
					'popup' => $this->model_tool_image->resize($result['image'], 291, 385),
					//'thumb' => $this->model_tool_image->resize($result['image'], 70, 78)
                    'thumb' => $this->model_tool_image->resize($result['image'], 67, 78),
					//'popup' => $this->model_tool_image->resize($result['image'] , $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
					//'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')),                   
				);
			}

			//Addwish + Canonical link
			$this->document->links = array();	
			$this->document->links[] = array(
				'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $this->request->get['product_id']),
				'rel'  => 'canonical'
			);
			$this->document->links[] = array(
				'href'	=> '<meta property="og:title" content="'.$product_info['name'].'"/>',
				'rel'	=> 'addwish_meta_tags',
			);
			$this->document->links[] = array(
				'href'	=> '<meta property="og:image" content="'.$this->data['thumb'].'"/>',
				'rel'	=> 'addwish_meta_tags',
			);
			$this->document->links[] = array(
				'href'	=> '<meta property="og:price" content="'.$this->data['price'].'"/>',
				'rel'	=> 'addwish_meta_tags',
			);
			
			$this->data['colors'] = array();
            $this->data['colors_option_id'] = 0;
           
			if(isset($this->request->get['color_id'])) {
				$this->data['current_color'] = $this->request->get['color_id'];             
			}
			else{
				$this->data['current_color'] = 0;
			}
					
            $this->data['video'] = false; //$product_info['video'] ? HTTPS_IMAGE . $product_info['video'] : '';
			$this->data['youtube_video'] = trim($product_info['youtube_video']) ? $product_info['youtube_video'] : '';
			$this->data['youtube_video_width'] = (int)$product_info['youtube_video_width'] ? $product_info['youtube_video_width'] : 300;
			$this->data['youtube_video_height'] = (int)$product_info['youtube_video_height'] ? $product_info['youtube_video_height'] : 315;
            $this->data['video_thumb'] = $this->model_tool_image->resize('flv_icon.png', 70, 78); 
            $this->data['text_video_thumb'] = $this->language->get('text_video_thumb');  
            
            $length_class = $this->model_catalog_product->getProductLengthClass($product_info['length_class_id']);
            $this->data['length'] = number_format($product_info['length']); 
            $this->data['width'] = number_format($product_info['width']); 
            $this->data['height'] = number_format($product_info['height']); 
            $this->data['length_class'] = $length_class;
            
            $weight_class = $this->model_catalog_product->getProductWeightClass($product_info['weight_class_id']);
            $this->data['weight'] = number_format($product_info['weight']); 
            $this->data['weight_class'] = $weight_class;
			            
            $this->data['product_number'] = $product_info['product_number'];
			$this->data['delay_delivery'] = $product_info['delay_delivery'];
            
            /*
            $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
            if(!empty($manufacturer_info)){
                $this->data['manufacturer_desc'] = html_entity_decode($manufacturer_info['description'], ENT_QUOTES, 'UTF-8');
            }
            else{
                $this->data['manufacturer_desc'] = '';
            }
            */
            $this->data['manufacturer_desc'] = html_entity_decode($product_info['manufacturer_desc'], ENT_QUOTES, 'UTF-8');
            
			$this->data['products'] = array();			
			

			if (!$this->config->get('config_customer_price')) {
				$this->data['display_price'] = TRUE;
			} elseif ($this->customer->isLogged()) {
				$this->data['display_price'] = TRUE;

			} else {
				$this->data['display_price'] = FALSE;
			}
			
            $url = HTTP_SERVER . 'index.php?route=product/' . ($path ? 'category' . $path : 'categories');
            $this->data['back'] = $this->model_tool_seo_url->rewrite($url);     
            $this->data['product_category'] = $path;                          
            $back_path = ($path ? $path : '') . '&product_id=' . $this->request->get['product_id'];             
            $this->session->data['go_back_product'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path;            
            $this->session->data['go_back_category'] = HTTP_SERVER . 'index.php?route=product/category' . $path;		
			$this->data['product_link'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path;
			$this->data['normal_view'] = HTTP_SERVER . 'index.php?route=product/product' . $back_path;
            $this->data['zoom_view'] = HTTP_SERVER . 'index.php?route=product/product/zoom' . $back_path;
            
			$this->model_catalog_product->updateViewed($this->request->get['product_id']); 			
			$this->data['tags'] = array();          					
			$results = $this->model_catalog_product->getProductTags($this->request->get['product_id']);
			
            $this->data['breadcrumbs'] = $this->document->breadcrumbs;
            $this->data['allow_stock_checkout'] = !$this->config->get('config_stock_checkout') && false;            
			
			foreach ($results as $result) {
				if ($result['tag']) {
					$this->data['tags'][] = array(
						'tag'	=> $result['tag'],
						'href'	=> HTTP_SERVER . 'index.php?route=product/search&keyword=' . $result['tag']
					);
				}
			}
			
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/productpopup.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/product/productpopup.tpl';
			} else {
				$this->template = 'default/template/product/productpopup.tpl';
			}
			$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
		}
    }
}
?>
